package com.marcelovelit.android;

import java.util.Calendar;

import android.os.Bundle;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class HomeActivity extends Activity {

	Button btn_aceptar;
	TextView tx_calcFecha, tx_mifecha;
	private int myYear, myMonth, myDay;
	static final int ID_DATEPICKER = 0;
	String date = "";
	Intent intent = null;

	RelativeLayout btn_opc1 = null;
	RelativeLayout btn_opc2 = null;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);

		TextView txtTitulo = (TextView) findViewById(R.id.titulo_cab);
		txtTitulo.setText("MI EMBARAZO");

		tx_calcFecha = (TextView) findViewById(R.id.tx_calcFecha);
		tx_mifecha = (TextView) findViewById(R.id.tx_mifechaes);

		btn_opc1 = (RelativeLayout) findViewById(R.id.btn_opc1);
		btn_opc2 = (RelativeLayout) findViewById(R.id.btn_opc2);

		btn_aceptar = (Button) findViewById(R.id.btn_aceptar);
		btn_aceptar.setVisibility(View.GONE);
		btn_aceptar.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				intent = new Intent(HomeActivity.this, MenuActivity.class);
				startActivity(intent);
				HomeActivity.this.finish();
			}
		});

		btn_opc1.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				final Calendar c = Calendar.getInstance();
				myYear = c.get(Calendar.YEAR);
				myMonth = c.get(Calendar.MONTH);
				myDay = c.get(Calendar.DAY_OF_MONTH);
				showDialog(ID_DATEPICKER);
				tx_calcFecha.setText("");
			}
		});

		btn_opc2.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				final Calendar c = Calendar.getInstance();
				myYear = c.get(Calendar.YEAR);
				myMonth = c.get(Calendar.MONTH);
				myDay = c.get(Calendar.DAY_OF_MONTH);
				showDialog(ID_DATEPICKER);
				tx_mifecha.setText("");
			}
		});

	}

	protected Dialog onCreateDialog(int id) {
		// TODO Auto-generated method stub
		switch (id) {
		case ID_DATEPICKER:

			return new DatePickerDialog(this, myDateSetListener1, myYear,
					myMonth, myDay);
		default:
			return null;
		}
	}

	private DatePickerDialog.OnDateSetListener myDateSetListener1 = new DatePickerDialog.OnDateSetListener() {

		public void onDateSet(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			// TODO Auto-generated method stub

			date = String.valueOf(dayOfMonth) + "/"
					+ String.valueOf(monthOfYear + 1) + "/"
					+ String.valueOf(year);

			if (tx_calcFecha.getText().equals("")) {
				tx_mifecha.setText(R.string.selec_fecha);
				tx_calcFecha.setText(date);
			}
			if (tx_mifecha.getText().equals("")) {

				tx_mifecha.setText(date);
				tx_calcFecha.setText(R.string.selec_fecha);
			}

			// tx_fecha.setText(date);
			btn_aceptar.setVisibility(View.VISIBLE);
			// Toast.makeText(HomeActivity.this, date,
			// Toast.LENGTH_LONG).show();
		}
	};
}